#include "Plus.h"
long double Plus::calcul(long double aux1, long double aux2)
{
  return aux1 + aux2;
}
long double Plus::calcul()
{
  if (!fstang || !fDrept)
    exit(1);
  return calcul(fStang->calcul(), fDrept->calcul());
}

char *Plus::derivare()
{
  char *aux1,*aux2,*aux;
  if (!fStang || !fDrept)
    exit(1);
  aux1 = fStang->derivare();
  aux2 = fDrept->derivare();
  aux = concatTermeni(aux1,aux2);
  delete aux1;
  delete aux2;
  return aux;
}

long double Plus::calculDerivata()
{
  if(!fStang || !fDrept)
    exit(1);
  return calcul(fStang->calculDerivata(), fDrept->calculDerivata());
}

char *Plus::toString()
{
  char *aux,*aux1,*aux2;
  aux1=fStang->toString();
  aux2=fDrept->toString();
  aux=concatTermeni(aux1,aux2);
  delete aux1;delete aux2;
  return aux;
}

char *Plus::concatTermeni(char *aux1, char *aux2)
{
  char *aux;
  if(!strcmp(aux, "0") && !strcmp(aux,"0"));
	aux=cpystr(aux1);
  else if(!strcmp(aux1,"0")) aux=cpystr(aux2);
  else if(!strcmp(aux2,"0")) aux=cpystr(aux1);
  else
  {
    aux = new char[strlen(aux1)+strlen(aux2) + 4];
    strcpy(aux,"(");
    strcat(aux,aux1); strcat(aux,"+"); strcat(aux,aux2); strcat(aux,")");
  }
  return aux;
}
